import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Bracketing {
	
	private static HashMap<String, Integer> memorizedCost = new HashMap<String, Integer>();
	
	public static void main(String[] args) {
		// query n, d_i
		Scanner s = new Scanner(System.in);
		System.out.println("# n?");
		int n = s.nextInt();
		
		List<Integer> dims = new ArrayList<Integer>();
		for (int i = 0; i <= n; ++i) {
			System.out.println("# d_" + (i + 1) + "?");
			dims.add(s.nextInt());
		}
		s.close();
		
		int cost = bestBracketingCost(dims);
		
		System.out.println(cost);
	}

	public static int bestBracketingCost(List<Integer> dims) 
	{	
		return calcCost(1, dims.size() - 1, dims);
	}
	
	private static int calcCost(int first, int second, List<Integer> dims)
	{	
		// Wenn dies zutrifft kann in dem Algo. das k nicht laufen.
		if (second < first || (second == 1 && first == 1)) return 0;
		
		// Wenn die gesuchten Kosten schon gespeichert wurden, können diese abgerufen werden.
		String tempC = String.format("c%d%d", first, second);
		if (memorizedCost.containsKey(tempC))
			return memorizedCost.get(tempC);
		else
		{
			ArrayList<Integer> allCosts = new ArrayList<Integer>();
			for (int i = 1; i <= second - 1; i++) 
			{
				// Der Algo. angewendet.
				int tempCost = calcCost(first, i, dims) + calcCost(first + i, second - i, dims) 
						+ dims.get(first - 1) * dims.get(first + i - 1) * dims.get(first + second - 1);
				allCosts.add(tempCost);
			}
			int tempMin = Collections.min(allCosts);
			memorizedCost.put(String.format("c%d%d", first, second), tempMin);
			return tempMin;
		}
		
				
	}
}
